######################################set linux compile env #############################
ifeq ($(strip $(targetbase)),linux)
include $(MK_DIR)/sys.mk
OBJ_DIR=$(OBJ_BASE_DIR)/app
__LIB_DIR := $(LIB_DIR)

PROG = ctcsdk
ifeq ($(ASW_ALONE), yes)
SRCS = ctc_app_asw_main.c
else
SRCS = ctc_app_main.c
endif

CPPFLAGS += -I$(SDK_DIR)/sal/include
CPPFLAGS += -I$(SDK_DIR)/dal/include
CPPFLAGS += -I$(SDK_DIR)/ctccli/sdkcli/asw
CPPFLAGS += -I$(SDK_DIR)/core
CPPFLAGS += -I$(SDK_DIR)/libctccli/include
CPPFLAGS += -I$(SDK_DIR)/ctccli/sdkcli
CPPFLAGS += -I$(SDK_DIR)/app
CPPFLAGS += -I$(SDK_DIR)/app/config
CPPFLAGS += -I$(SDK_DIR)/app/usr
CPPFLAGS += -I$(SDK_DIR)/app/sample
CPPFLAGS += $(foreach n, $(chipname), -I$(SDK_DIR)/ctccli/sdkcli/$(n))
CPPFLAGS += -I$(SDK_DIR)/libptkxr/include
CPPFLAGS += -I$(SDK_DIR)/core/common/include

LIBSAL    = $(LIB_DIR)/libsal.a
LIBDAL    = $(LIB_DIR)/libdal.a
LIBSDK    = $(LIB_DIR)/libsdkcore.a
LIBDRV    = $(LIB_DIR)/libdrv.a
LIBAPP    = $(LIB_DIR)/libapp.a

LIBLIBCTCCLI  = $(LIB_DIR)/liblibctccli.a
LIBCTCCLI  = $(LIB_DIR)/libctccli.a

LIBDKIT = $(LIB_DIR)/libdkit.a

ifeq ($(strip $(SO_LIB)),yes)
LIBCTCSDK = $(LIB_DIR)/libctcsdk.so
else
LIBCTCSDK = $(LIB_DIR)/libctcsdk.a
endif

ifeq ($(CTC_PHY_EN),yes)
LIBPHY = $(LIB_DIR)/libphy.a
endif

LD_FLAGS += -Wl,--rpath=$(RPATH)

ifeq ($(strip $(ONE_LIB)),yes)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -lctcsdk
ifeq ($(APP_IN_SDK), no)
LD_LIBS += -lapp
endif
else
DEP_LIBS = $(LIBAPP)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -lapp
ifeq ($(strip $(PUMP)), TRUE)
DEP_LIBS += $(LIB_DIR)/libpump.a
LD_LIBS += -lpump
endif
endif

ifeq ($(strip $(BOARD)),ctc-sim)
        ifneq ($(cpp),no)
	LD_LIBS += -L$(CMODEL_DIR)/build.$(CPU).$(VER)/$(chipname)/lib.$(BOARD)
        LIBCMODEL = $(CMODEL_DIR)/build.$(CPU).$(VER)/$(chipname)/lib.$(BOARD)/libcmodel.a
        else
	LD_LIBS += -L/data01/workspace/sdk/libcmodel/$(chipname).57x
	LIBCMODEL = /data01/workspace/sdk/libcmodel/$(chipname).57x/libcmodel.a
	endif
endif

ifeq ($(strip $(ONE_LIB)), yes)
ifeq ($(strip $(BOARD)),ctc-sim)
DEP_LIBS += $(LIBCMODEL) $(LIBCTCSDK)
LD_LIBS += -Wl,--start-group,-lcmodel,-lctcsdk,--end-group -lpthread -ldl -lm
else
DEP_LIBS += $(LIBCTCSDK)
LD_LIBS += -Wl,--start-group,-lctcsdk,--end-group -lpthread -ldl -lm
endif
else

ifeq ($(strip $(eunit_sim)), yes)
LD_LIBS += -L$(SDK_DIR)/../esdk/build.$(CPU).$(VER)/lib.$(BOARD)
LIBEUNIT = $(LIB_DIR)/libeunitsim.a
else
LIBEUNIT =
endif

ifeq ($(strip $(BOARD)),ctc-sim)

DEP_LIBS += $(LIBCMODEL) $(LIBEUNIT) $(LIBCTCCLI) $(LIBAPP)  $(LIBSDK) $(LIBDRV) $(LIBDAL) $(LIBSAL) $(LIBDKIT)
ifeq ($(strip $(eunit_sim)), yes)
LD_LIBS += -Wl,--start-group,-lctccli,-lcmodel,-leunitsim,-llibctccli,-lapp,-lsdkcore,-ldrv,-lsal,-ldal,-ldkit,--end-group -lpthread -ldl -lm
else
LD_LIBS += -Wl,--start-group,-lctccli,-lcmodel,-llibctccli,-lapp,-lsdkcore,-ldrv,-lsal,-ldal,-ldkit,--end-group -lpthread -ldl -lm
endif

else
ifeq ($(CTC_CLI_EN),yes)
DEP_LIBS += $(LIBLIBCTCCLI) $(LIBCTCCLI)
LD_LIBS += -lctccli -llibctccli
endif
ifeq ($(CTC_PHY_EN),yes)
DEP_LIBS += $(LIBPHY)
LD_LIBS += -lphy
endif
DEP_LIBS += $(LIBAPP) $(LIBSDK) $(LIBDRV) $(LIBDAL) $(LIBSAL)
LD_LIBS += -Wl,--start-group,-lapp,-lsdkcore,-ldrv,-lsal,-ldal,--end-group -lpthread -ldl -lm
ifneq ($(ASW_ALONE), yes)
DEP_LIBS +=  $(LIBDKIT)
LD_LIBS += -Wl,--start-group,-ldkit,--end-group
endif
LD_LIBS += -lpthread -ldl -lm
endif
endif

ifeq ($(strip $(PUMP)), TRUE)
ifeq ($(strip $(CTC_SAMPLE)), TRUE)
LD_LIBS += -lcurl -lrt
endif
endif

ifeq ($(strip $(BOARD)),ctc-sim)
ifeq ($(strip $(M64)),TRUE)
LIB_LCRYPTO_DIR := $(CMODEL_DIR)/$(CHIPNAME)/lib/lib64
LD_LIBS += -L$(LIB_LCRYPTO_DIR) -lcrypto -lpthread -ldl -lstdc++ -lm
else
LIB_LCRYPTO_DIR := $(CMODEL_DIR)/$(CHIPNAME)/lib/lib32
LD_LIBS += -L$(LIB_LCRYPTO_DIR) -lcrypto -lpthread -ldl -lstdc++ -lm
endif
endif

include $(MK_DIR)/prog.mk
endif

######################################set vxworks compile env #############################
ifeq ($(strip $(targetbase)),vxworks)

OBJ_DIR=$(OBJ_BASE_DIR)/app
ifeq ($(LINK),yes)
all_targets = sample config sdkinit ctcsdk vxworks
else
all_targets = sample config sdkinit ctcsdk
endif

all: $(all_targets) FORCE
clean: $(addprefix clean_,$(all_targets)) FORCE


usr: FORCE
	make -C $(SDK_DIR)/app/usr -f Makefile.vx

clean_usr: FORCE
	make -C $(SDK_DIR)/app/usr -f Makefile.vx clean

sample: FORCE
	make -C $(SDK_DIR)/app/sample -f Makefile.vx

clean_sample: FORCE
	make -C $(SDK_DIR)/app/sample -f Makefile.vx clean

config: FORCE
	make -C $(SDK_DIR)/app/config -f Makefile.vx

config_sample: FORCE
	make -C $(SDK_DIR)/app/config -f Makefile.vx clean

sdkinit: FORCE
	make -f Makefile.vx

clean_sdkinit: FORCE
	make -f Makefile.vx clean

ctcsdk: FORCE
	make -f Makefile_sdk.vx

clean_ctcsdk: FORCE
	make -f Makefile_sdk.vx clean

vxworks: FORCE
	make -f Makefile_vx

clean_vxworks: FORCE
	make -f Makefile_vx clean

.PHONY: FORCE
FORCE:
endif
